<?php

if(!defined('IN_UCHOME')) {
	exit('Access Denied');
}

//检查信息
$op = empty($_GET['op'])?'jobring':$_GET['op'];

$poll = array();
$_SCONFIG['maxreward'] = $_SCONFIG['maxreward'] < 2 ? 10 : $_SCONFIG['maxreward'];
$hrid = empty($_GET['id'])?0:intval($_GET['id']);

//权限检查
if(empty($poll)) {

	if(!checkperm('allowpoll')) {
		ckspacelog();
		showmessage('no_authority_to_add_poll');
	}

	//实名认证
	ckrealname('poll');
	
	//视频认证
	ckvideophoto('poll');

	//新用户见习
	cknewuser();

	//判断是否发布太快
	$waittime = interval_check('post');
	if($waittime > 0) {
		showmessage('operating_too_fast','',1,array($waittime));
	}
}

if ($op == 'hrwanted') {

	if(submitcheck('jobhrwanted')) {

		//验证码
		if(!ckseccode($_POST['seccode'])) {
			showmessage('incorrect_code');
		}

		$_POST['position'] = getstr(trim($_POST['position']), 80, 1, 1, 1);
		if(strlen($_POST['position']) < 2) showmessage('title_not_too_little');
		$_POST['location'] = $_POST['province']."--".$_POST['city'];
		$_POST['edu'] = getstr(trim($_POST['edu']), 80, 1, 1, 1);
		$_POST['work_age'] = getstr(trim($_POST['work_age']), 80, 1, 1, 1);
		$_POST['salary'] = getstr(trim($_POST['salary']), 80, 1, 1, 1);
		$_POST['certificate'] = getstr(trim($_POST['certificate']), 80, 1, 1, 1);
		$_POST['beizhu'] = getstr(trim($_POST['beizhu']), 0, 1, 1, 1, 2);
		$_POST['claim'] = getstr(trim($_POST['claim']), 0, 1, 1, 1, 2);

		$setarr = array(
			'uid'			=> $_SGLOBAL['supe_uid'],
			'name'			=> $_SGLOBAL['supe_username'],
			'position'		=> $_POST['position'],
			'location'		=> $_POST['location'],
			'edu'			=> $_POST['edu'],
			'work_age'		=> $_POST['work_age'],
			'salary'		=> $_POST['salary'],
			'certificate'	=> $_POST['certificate'],
			'beizhu'		=> $_POST['beizhu'],
			'claim'			=> $_POST['claim'],
			'dateline'		=> $_SGLOBAL['timestamp'],
			'status'		=> 2
		);

		$hwid = inserttable('hrbring', $setarr, 1);

		include_once(S_ROOT.'./source/function_feed.php');
		feed_publish($hwid, 'hwid', 1);

		showmessage('do_success', "space.php?do=hr&fc=$op", 0);

	}

} elseif ($op == 'hrbring') {
	
	//提交该请求以后，需要检查该用户是否加入公司，暂时未做
	if(submitcheck('jobhrbring')) {

		//验证码
		if(!ckseccode($_POST['seccode'])) {
			showmessage('incorrect_code');
		}

		$_POST['position'] = getstr(trim($_POST['position']), 80, 1, 1, 1);
		if(strlen($_POST['position']) < 2) showmessage('title_not_too_little');
		$_POST['location'] = $_POST['province']."--".$_POST['city'];
		$_POST['edu'] = getstr(trim($_POST['edu']), 80, 1, 1, 1);
		$_POST['work_age'] = getstr(trim($_POST['work_age']), 80, 1, 1, 1);
		$_POST['salary'] = getstr(trim($_POST['salary']), 80, 1, 1, 1);
		$_POST['certificate'] = getstr(trim($_POST['certificate']), 80, 1, 1, 1);
		$_POST['duty'] = getstr(trim($_POST['duty']), 0, 1, 1, 1, 2);
		$_POST['claim'] = getstr(trim($_POST['claim']), 0, 1, 1, 1, 2);
		$_POST['num'] = abs(intval($_POST['num']));

		$expiration = 0;
		if($_POST['endtime']) {
			$expiration = sstrtotime(trim($_POST['endtime']).' 23:59:59');
			if($expiration <= $_SGLOBAL['timestamp']) {
				showmessage('time_expired_error');
			}
		}
		$setarr = array(
			'uid'			=> $_SGLOBAL['supe_uid'],
			'name'			=> $_SGLOBAL['supe_username'],
			'position'		=> $_POST['position'],
			'location'		=> $_POST['location'],
			'edu'			=> $_POST['edu'],
			'work_age'		=> $_POST['work_age'],
			'salary'		=> $_POST['salary'],
			'certificate'	=> $_POST['certificate'],
			'duty'			=> $_POST['duty'],
			'claim'			=> $_POST['claim'],
			'num'			=> $_POST['num'],
			'endtime'		=> $expiration,
			'dateline'		=> $_SGLOBAL['timestamp'],
			'status'		=> 1
		);

		$hrid = inserttable('hrbring', $setarr, 1);
		include_once(S_ROOT.'./source/function_feed.php');
		feed_publish($hrid, 'hrid', 1);

		showmessage('do_success', "space.php?do=hr&fc=$op", 0);

	}

} elseif ($op == 'jobwant') {

	if(submitcheck('jobjobwant')) {

		//验证码
		if(!ckseccode($_POST['seccode'])) {
			showmessage('incorrect_code');
		}

		$_POST['position'] = getstr(trim($_POST['position']), 80, 1, 1, 1);
		if(strlen($_POST['position']) < 2) showmessage('title_not_too_little');
		$_POST['location'] = $_POST['province']."--".$_POST['city'];
		$_POST['certificate'] = getstr(trim($_POST['certificate']), 80, 1, 1, 1);
		$_POST['cert_level'] = getstr(trim($_POST['cert_level']), 80, 1, 1, 1);
		$_POST['ship_age'] = getstr(trim($_POST['ship_age']), 80, 1, 1, 1);
		$_POST['dwt'] = getstr(trim($_POST['dwt']), 80, 1, 1, 1);
		$_POST['shiptype'] = getstr(trim($_POST['shiptype']), 80, 1, 1, 1);
		$_POST['salary'] = getstr(trim($_POST['salary']), 80, 1, 1, 1);
		$_POST['regional_route'] = getstr(trim($_POST['regional_route']), 80, 1, 1, 1);
		$_POST['beizhu'] = getstr(trim($_POST['beizhu']), 0, 1, 1, 1, 2);

		$setarr = array(
			'uid'			=> $_SGLOBAL['supe_uid'],
			'name'			=> $_SGLOBAL['supe_username'],
			'position'		=> $_POST['position'],
			'location'		=> $_POST['location'],
			'certificate'	=> $_POST['certificate'],
			'cert_level'	=> $_POST['cert_level'],
			'ship_age'		=> $_POST['ship_age'],
			'dwt'			=> $_POST['dwt'],
			'shiptype'		=> $_POST['shiptype'],
			'salary'		=> $_POST['salary'],
			'regional_route'	=> $_POST['regional_route'],
			'beizhu'		=> $_POST['beizhu'],
			'dateline'		=> $_SGLOBAL['timestamp'],
			'status'		=> 2
		);

		$jwid = inserttable('boatman', $setarr, 1);
		include_once(S_ROOT.'./source/function_feed.php');
		feed_publish($jwid, 'jwid', 1);

		showmessage('do_success', "space.php?do=hr&fc=$op", 0);

	}

} elseif ($op == 'jobring') {

	if(submitcheck('jobjobring')) {

		//验证码
		if(checkperm('seccode') && !ckseccode($_POST['seccode'])) {
			showmessage('incorrect_code');
		}

		$_POST['position'] = getstr(trim($_POST['position']), 80, 1, 1, 1);
		if(strlen($_POST['position']) < 2) showmessage('title_not_too_little');
		$_POST['location'] = $_POST['province']."--".$_POST['city'];
		$_POST['certificate'] = getstr(trim($_POST['certificate']), 80, 1, 1, 1);
		$_POST['cert_level'] = getstr(trim($_POST['cert_level']), 80, 1, 1, 1);
		$_POST['ship_age'] = getstr(trim($_POST['ship_age']), 80, 1, 1, 1);
		$_POST['dwt'] = getstr(trim($_POST['dwt']), 80, 1, 1, 1);
		$_POST['shiptype'] = getstr(trim($_POST['shiptype']), 80, 1, 1, 1);
		$_POST['salary'] = getstr(trim($_POST['salary']), 80, 1, 1, 1);
		$_POST['regional_route'] = getstr(trim($_POST['regional_route']), 80, 1, 1, 1);
		$_POST['beizhu'] = getstr(trim($_POST['beizhu']), 0, 1, 1, 1, 2);

		$setarr = array(
			'uid'			=> $_SGLOBAL['supe_uid'],
			'name'			=> $_SGLOBAL['supe_username'],
			'position'		=> $_POST['position'],
			'location'		=> $_POST['location'],
			'certificate'	=> $_POST['certificate'],
			'cert_level'	=> $_POST['cert_level'],
			'ship_age'		=> $_POST['ship_age'],
			'dwt'			=> $_POST['dwt'],
			'shiptype'		=> $_POST['shiptype'],
			'salary'		=> $_POST['salary'],
			'regional_route'	=> $_POST['regional_route'],
			'beizhu'		=> $_POST['beizhu'],
			'dateline'		=> $_SGLOBAL['timestamp'],
			'status'		=> 1
		);

		$toshiptime = 0;
		if($_POST['toshiptime']) {
			$toshiptime = sstrtotime(trim($_POST['toshiptime']).' 23:59:59');
			if($toshiptime <= $_SGLOBAL['timestamp']) {
				showmessage('time_expired_error');
			}
			$setarr['toshiptime'] = $toshiptime;
		}
		$endtime = 0;
		if($_POST['endtime']) {
			$endtime = sstrtotime(trim($_POST['endtime']).' 23:59:59');
			if($endtime <= $_SGLOBAL['timestamp']) {
				showmessage('time_expired_error');
			}
			$setarr['endtime'] = $endtime;
		}

		$jbid = inserttable('boatman', $setarr, 1);
		include_once(S_ROOT.'./source/function_feed.php');
		feed_publish($jbid, 'jbid', 1);
		showmessage('do_success', "space.php?do=hr&fc=$op", 0);

	}

} elseif ($op == 'editjobring') {

	if(submitcheck('editjobring')) {

		//验证码
		if(!ckseccode($_POST['seccode'])) {
			showmessage('incorrect_code');
		}

		$_POST['position'] = getstr(trim($_POST['position']), 80, 1, 1, 1);
		if(strlen($_POST['position']) < 2) showmessage('title_not_too_little');
		$_POST['location'] = $_POST['province']."--".$_POST['city'];
		$_POST['certificate'] = getstr(trim($_POST['certificate']), 80, 1, 1, 1);
		$_POST['cert_level'] = getstr(trim($_POST['cert_level']), 80, 1, 1, 1);
		$_POST['ship_age'] = getstr(trim($_POST['ship_age']), 80, 1, 1, 1);
		$_POST['dwt'] = getstr(trim($_POST['dwt']), 80, 1, 1, 1);
		$_POST['shiptype'] = getstr(trim($_POST['shiptype']), 80, 1, 1, 1);
		$_POST['salary'] = getstr(trim($_POST['salary']), 80, 1, 1, 1);
		$_POST['regional_route'] = getstr(trim($_POST['regional_route']), 80, 1, 1, 1);
		$_POST['beizhu'] = getstr(trim($_POST['beizhu']), 0, 1, 1, 1, 2);

		$setarr = array(
			'position'		=> $_POST['position'],
			'location'		=> $_POST['location'],
			'certificate'	=> $_POST['certificate'],
			'cert_level'	=> $_POST['cert_level'],
			'ship_age'		=> $_POST['ship_age'],
			'dwt'			=> $_POST['dwt'],
			'shiptype'		=> $_POST['shiptype'],
			'salary'		=> $_POST['salary'],
			'regional_route'	=> $_POST['regional_route'],
			'beizhu'		=> $_POST['beizhu']
		);

		updatetable('boatman', $setarr, array('id'=>intval($_POST['id']),'uid'=>$_SGLOBAL['supe_uid']));

		showmessage('do_success', "space.php?do=hr&fc=".substr($op, 4), 0);

	}else{
		include_once(S_ROOT.'./source/function_hr.php');
		if($hrid<1){
			showmessage('do_failed','space.php?do=hr&fc=jobring&view=my',0);
		}

		$hr = gethr('boatman', array('id'=>$hrid, 'status'=>'1', 'uid'=>$_SGLOBAL['supe_uid']));
		$location = explode('--', $hr['location']);
		$hr['province'] = $location[0];
		$hr['city'] = $location[1];
		$op = 'jobring';
	}

} elseif ($op == 'edithrbring') {

	if(submitcheck('edithrbring')) {

		//验证码
		if(!ckseccode($_POST['seccode'])) {
			showmessage('incorrect_code');
		}

		$_POST['position'] = getstr(trim($_POST['position']), 80, 1, 1, 1);
		if(strlen($_POST['position']) < 2) showmessage('title_not_too_little');
		$_POST['location'] = $_POST['province']."--".$_POST['city'];
		$_POST['edu'] = getstr(trim($_POST['edu']), 80, 1, 1, 1);
		$_POST['work_age'] = getstr(trim($_POST['work_age']), 80, 1, 1, 1);
		$_POST['salary'] = getstr(trim($_POST['salary']), 80, 1, 1, 1);
		$_POST['certificate'] = getstr(trim($_POST['certificate']), 80, 1, 1, 1);
		$_POST['beizhu'] = getstr(trim($_POST['beizhu']), 0, 1, 1, 1, 2);
		$_POST['claim'] = getstr(trim($_POST['claim']), 0, 1, 1, 1, 2);

		$setarr = array(
			'position'		=> $_POST['position'],
			'location'		=> $_POST['location'],
			'edu'			=> $_POST['edu'],
			'work_age'		=> $_POST['work_age'],
			'salary'		=> $_POST['salary'],
			'certificate'	=> $_POST['certificate'],
			'beizhu'		=> $_POST['beizhu'],
			'claim'			=> $_POST['claim']
		);

		updatetable('hrbring', $setarr, array('id'=>intval($_POST['id']),'uid'=>$_SGLOBAL['supe_uid']));

		showmessage('do_success', "space.php?do=hr&fc=".substr($op, 4), 0);

	}else{
		include_once(S_ROOT.'./source/function_hr.php');
		if($hrid<1){
			showmessage('do_failed','space.php?do=hr&fc=hrbring&view=my',0);
		}

		$hr = gethr('hrbring', array('id'=>$hrid, 'status'=>'1', 'uid'=>$_SGLOBAL['supe_uid']));
		$location = explode('--', $hr['location']);
		$hr['province'] = $location[0];
		$hr['city'] = $location[1];

		$op = 'hrbring';
	}

} elseif ($op == 'editjobwant') {

	if(submitcheck('editjobwant')) {

		//验证码
		if(!ckseccode($_POST['seccode'])) {
			showmessage('incorrect_code');
		}

		$_POST['position'] = getstr(trim($_POST['position']), 80, 1, 1, 1);
		if(strlen($_POST['position']) < 2) showmessage('title_not_too_little');
		$_POST['location'] = $_POST['province']."--".$_POST['city'];
		$_POST['certificate'] = getstr(trim($_POST['certificate']), 80, 1, 1, 1);
		$_POST['cert_level'] = getstr(trim($_POST['cert_level']), 80, 1, 1, 1);
		$_POST['ship_age'] = getstr(trim($_POST['ship_age']), 80, 1, 1, 1);
		$_POST['dwt'] = getstr(trim($_POST['dwt']), 80, 1, 1, 1);
		$_POST['shiptype'] = getstr(trim($_POST['shiptype']), 80, 1, 1, 1);
		$_POST['salary'] = getstr(trim($_POST['salary']), 80, 1, 1, 1);
		$_POST['regional_route'] = getstr(trim($_POST['regional_route']), 80, 1, 1, 1);
		$_POST['beizhu'] = getstr(trim($_POST['beizhu']), 0, 1, 1, 1, 2);

		$setarr = array(
			'position'		=> $_POST['position'],
			'location'		=> $_POST['location'],
			'certificate'	=> $_POST['certificate'],
			'cert_level'	=> $_POST['cert_level'],
			'ship_age'		=> $_POST['ship_age'],
			'dwt'			=> $_POST['dwt'],
			'shiptype'		=> $_POST['shiptype'],
			'salary'		=> $_POST['salary'],
			'regional_route'	=> $_POST['regional_route'],
			'beizhu'		=> $_POST['beizhu']
		);

		updatetable('boatman', $setarr, array('id'=>intval($_POST['id']),'uid'=>$_SGLOBAL['supe_uid']));

		showmessage('do_success', "space.php?do=hr&fc=".substr($op, 4), 0);

	}else{
		include_once(S_ROOT.'./source/function_hr.php');
		if($hrid<1){
			showmessage('do_failed','space.php?do=hr&fc=jobwant&view=my',0);
		}

		$hr = gethr('boatman', array('id'=>$hrid, 'status'=>'2', 'uid'=>$_SGLOBAL['supe_uid']));
		$location = explode('--', $hr['location']);
		$hr['province'] = $location[0];
		$hr['city'] = $location[1];

		$op = 'jobwant';
	}

} elseif ($op == 'edithrwanted') {

	if(submitcheck('edithrwanted')) {

		//验证码
		if(!ckseccode($_POST['seccode'])) {
			showmessage('incorrect_code');
		}

		$_POST['position'] = getstr(trim($_POST['position']), 80, 1, 1, 1);
		if(strlen($_POST['position']) < 2) showmessage('title_not_too_little');
		$_POST['location'] = $_POST['province']."--".$_POST['city'];
		$_POST['edu'] = getstr(trim($_POST['edu']), 80, 1, 1, 1);
		$_POST['work_age'] = getstr(trim($_POST['work_age']), 80, 1, 1, 1);
		$_POST['salary'] = getstr(trim($_POST['salary']), 80, 1, 1, 1);
		$_POST['certificate'] = getstr(trim($_POST['certificate']), 80, 1, 1, 1);
		$_POST['beizhu'] = getstr(trim($_POST['beizhu']), 0, 1, 1, 1, 2);
		$_POST['claim'] = getstr(trim($_POST['claim']), 0, 1, 1, 1, 2);

		$setarr = array(
			'position'		=> $_POST['position'],
			'location'		=> $_POST['location'],
			'edu'			=> $_POST['edu'],
			'work_age'		=> $_POST['work_age'],
			'salary'		=> $_POST['salary'],
			'certificate'	=> $_POST['certificate'],
			'beizhu'		=> $_POST['beizhu'],
			'claim'			=> $_POST['claim']
		);

		updatetable('hrbring', $setarr, array('id'=>intval($_POST['id']),'uid'=>$_SGLOBAL['supe_uid']));

		showmessage('do_success', "space.php?do=hr&fc=".substr($op, 4), 0);

	}else{
		include_once(S_ROOT.'./source/function_hr.php');
		if($hrid<1){
			showmessage('do_failed','space.php?do=hr&fc=hrwangted&view=my',0);
		}

		$hr = gethr('hrbring', array('id'=>$hrid, 'status'=>'2', 'uid'=>$_SGLOBAL['supe_uid']));
		$location = explode('--', $hr['location']);
		$hr['province'] = $location[0];
		$hr['city'] = $location[1];

		$op = 'hrwanted';
	}

} elseif ($op == 'delete') {

	if(submitcheck('deletesubmit')) {
		$hrid = empty($_POST['infoid'])?0:intval($_POST['infoid']);
		$sudo = empty($_POST['sudo'])?'':intval($_POST['sudo']);
		switch($sudo){
			case 'hw': $table = 'hrbring';break;
			case 'hb': $table = 'hrbring';break;
			case 'jw': $table = 'boatman';break;
			case 'jb': $table = 'boatman';break;
		}
		//删除
		$query = $_SGLOBAL['db']->query("DELETE FROM ".tname($table)." WHERE uid='".$_SGLOBAL['supe_uid']."' AND id='$hrid'");

		if($query){
			showmessage('do_success', $_POST['refer'], 1000);
		}else{
			showmessage('do_failed', $_POST['refer'], 2000);
		}
	}else{
		$fc = empty($_GET['fc'])?'':$_GET['fc'];

		if(!$fc){
			showmessage('do_failed', $_SGLOBAL['refer'],1000);
		}
	}

} elseif ($op == 'info_message') {

	if(submitcheck('info_submit')) {
		$msg['infoid'] = empty($_POST['infoid'])?'0':intval($_POST['infoid']);
		$msg['touid'] = empty($_POST['touid'])?'0':intval($_POST['touid']);
		$msg['flag'] = empty($_POST['flag'])?'':trim($_POST['flag']);
		$msg['fromuid'] = $_SGLOBAL['supe_uid'];
		$msg['message'] = getstr(trim($_POST['info_message']), 100, 1, 1, 1, 2);
		$msg['dateline'] = $_SGLOBAL['timestamp'];

		$mid = inserttable('info_message', $msg, 1);

		if($mid){
			showmessage('do_success', $_POST['refer'], 1000);
		}else{
			showmessage('do_failed', $_POST['refer'], 2000);
		}
	}

}

include_once template("cp_hr");

?>